package com.goodving.guli.bt.profile.scale;

import android.bluetooth.BluetoothGatt;
import android.support.v4.internal.view.SupportMenu;
import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;

import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.utils.ProfileUtils;
import com.goodving.guli.utility.Constants;
import com.goodving.guli.utility.gulihardware.Constant;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;

import java.lang.reflect.Field;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.UUID;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;

/**
 * Created by john on 2015/12/11.
 */
public class FrkGattUtils { //  C3892y
    public static final UUID f19564a;
    public static final UUID f19565b;
    public static UUID f19566c = null;
    public static UUID f19567d = null;
    private static final String TAG = "GattUtils";
    private static final String f19569f = "0000%4s-0000-1000-8000-00805f9b34fb";
    private static final String f19570g;
    private static final long f19571h = 4096;
    private static final long f19572i = -9223371485494954757L;
    private static final int[] f19573j;
    private static final byte BLE_FLAGS = (byte) 1;
    private static final byte BLE_INCOMPLETE_16BITS_UUID = (byte) 2;
    private static final byte BLE_COMPLETE_16BITS_UUID = (byte) 3;
    private static final byte BLE_INCOMPLETE_128BITS_UUID = (byte) 6;
    private static final byte BLE_COMPLETE_128BITS_UUID = (byte) 7;
    private static final byte BLE_SHORTENED_LOCAL_NAME = (byte) 8;
    private static final byte BLE_COMPLETE_LOCAL_NAME = (byte) 9;
    private static final byte BLE_TX_POWER_LEVEL = (byte) 10;
    private static final byte BLE_16BITS_SER_SOL_UUID = (byte) 20;
    private static final byte BLE_128BITS_SER_SOL_UUID = (byte) 21;
    private static final byte BLE_SERVICE_DATA = (byte) 22;
    private static final byte BLE_MANUFACTURE_SPEC_DATA = (byte) -1;
    private static Field mField;

    static {
        f19570g = String.format(f19569f, new Object[]{"...."});
        f19564a = GattUtils.m25322a("2902");
        f19565b = GattUtils.m25322a("2901");
        f19566c = new UUID(303230942, 1523193452336828707L);
        f19567d = new UUID(-1152921504534413312L, -5764607523034234880L);
        f19573j = new int[]{0, 49345, 49537, C4220a.by, 49921, 960, 640, 49729, 50689, 1728, 1920, 51009, 1280, 50625, 50305, 1088, 52225, 3264, 3456, 52545, 3840, 53185, 52865, 3648, 2560, 51905, 52097, 2880, 51457, 2496, 2176, 51265, 55297, 6336, 6528, 55617, 6912, 56257, 55937, 6720, 7680, 57025, 57217, C4220a.bS, 56577, 7616, 7296, 56385, 5120, 54465, 54657, 5440, 55041, 6080, 5760, 54849, 53761, 4800, 4992, 54081, 4352, 53697, 53377, 4160, 61441, 12480, 12672, 61761, 13056, 62401, 62081, 12864, 13824, 63169, 63361, 14144, 62721, 13760, 13440, 62529, 15360, 64705, 64897, 15680, C3867z.f19487h, 16320, 16000, 65089, 64001, 15040, 15232, 64321, 14592, 63937, 63617, 14400, 10240, 59585, 59777, 10560, 60161, 11200, 10880, 59969, 60929, 11968, 12160, 61249, 11520, 60865, 60545, 11328, 58369, 9408, 9600, 58689, 9984, 59329, 59009, 9792, 8704, 58049, 58241, 9024, 57601, 8640, 8320, 57409, 40961, 24768, 24960, 41281, 25344, 41921, 41601, 25152, 26112, 42689, 42881, 26432, 42241, 26048, 25728, 42049, 27648, 44225, 44417, 27968, 44801, 28608, 28288, 44609, 43521, 27328, 27520, 43841, 26880, 43457, 43137, 26688, 30720, 47297, 47489, 31040, 47873, 31680, 31360, 47681, 48641, 32448, 32640, 48961, Constant.df, 48577, 48257, 31808, 46081, 29888, 30080, 46401, 30464, 47041, 46721, 30272, 29184, 45761, 45953, 29504, 45313, 29120, 28800, 45121, 20480, 37057, 37249, 20800, 37633, 21440, 21120, 37441, 38401, 22208, 22400, 38721, 21760, 38337, 38017, 21568, 39937, 23744, 23936, 40257, 24320, 40897, 40577, 24128, 23040, 39617, 39809, 23360, 39169, 22976, 22656, 38977, 34817, 18624, 18816, 35137, 19200, 35777, 35457, 19008, 19968, 36545, 36737, 20288, 36097, 19904, 19584, 35905, 17408, 33985, 34177, 17728, 34561, 18368, 18048, 34369, 33281, 17088, 17280, 33601, 16640, 33217, 32897, 16448};
        mField = null;
    }

    public static int m25318a(int i, byte[] bArr, int i2, int i3) {
        while (i2 < i3) {
            int i4 = (((i >>> 8) | (i << 8)) & SupportMenu.USER_MASK) ^ (bArr[i2] & HeartRateInfo.HR_EMPTY_VALUE);
            i4 ^= (i4 & HeartRateInfo.HR_EMPTY_VALUE) >> 4;
            i4 ^= (i4 << 12) & SupportMenu.USER_MASK;
            i = i4 ^ (((i4 & HeartRateInfo.HR_EMPTY_VALUE) << 5) & SupportMenu.USER_MASK);
            i2++;
        }
        return i;
    }

    public static int printClientIf(BluetoothGatt bluetoothGatt) {
        if (mField == null) {
            try {
                mField = BluetoothGatt.class.getDeclaredField("mClientIf");
                mField.setAccessible(true);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
        try {
            return mField.getInt(bluetoothGatt);
        } catch (IllegalAccessException e2) {
            e2.printStackTrace();
            return -1;
        } catch (IllegalArgumentException e3) {
            e3.printStackTrace();
            return -1;
        }
    }

    public static int m25320a(byte[] bArr, int i) {
        return GattUtils.m25339c(bArr, i, 4);
    }

    public static UUID m25321a(int i) {
        return new UUID(((((long) i) & 4294967295L) << 32) | f19571h, f19572i);
    }

    public static UUID m25322a(String str) {
        return UUID.fromString(String.format(f19569f, new Object[]{str}));
    }

    public static UUID m25323a(UUID uuid, int i) {
        return GattUtils.m25324a(uuid, (short) i);
    }

    public static UUID m25324a(UUID uuid, short s) {
        return new UUID((uuid.getMostSignificantBits() & -281470681743361L) | ((((long) s) & 65535) << 32), uuid.getLeastSignificantBits());
    }

    public static UUID m25325a(short s) {
        return GattUtils.m25321a(SupportMenu.USER_MASK & s);
    }

    public static UUID m25326a(byte[] bArr) {
        switch (bArr.length) {
            case C4220a.f20888k /*2*/:
                return GattUtils.m25322a(String.format("%02x%02x", new Object[]{Byte.valueOf(bArr[0]), Byte.valueOf(bArr[1])}));
            case C4220a.bp /*16*/:
                StringBuilder stringBuilder = new StringBuilder(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
                stringBuilder.append(String.format("%02x%02x%02x%02x", new Object[]{Byte.valueOf(bArr[0]), Byte.valueOf(bArr[1]), Byte.valueOf(bArr[2]), Byte.valueOf(bArr[3])}));
                stringBuilder.append(String.format("-%02x%02x-%02x%02x", new Object[]{Byte.valueOf(bArr[4]), Byte.valueOf(bArr[5]), Byte.valueOf(bArr[6]), Byte.valueOf(bArr[7])}));
                stringBuilder.append(String.format("-%02x%02x-%02x%02x", new Object[]{Byte.valueOf(bArr[8]), Byte.valueOf(bArr[9]), Byte.valueOf(bArr[10]), Byte.valueOf(bArr[11])}));
                stringBuilder.append(String.format("%02x%02x%02x%02x", new Object[]{Byte.valueOf(bArr[12]), Byte.valueOf(bArr[13]), Byte.valueOf(bArr[14]), Byte.valueOf(bArr[15])}));
                return GattUtils.m25336b(stringBuilder.toString());
            default:
                return null;
        }
    }

    public static short m25327a(UUID uuid) {
        return (short) GattUtils.m25332b(uuid);
    }

    public static void m25328a(byte[] bArr, int i, int i2) {
        int i3 = i + 1;
        bArr[i] = (byte) ((i2 >> 0) & HeartRateInfo.HR_EMPTY_VALUE);
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >> 8) & HeartRateInfo.HR_EMPTY_VALUE);
        i3 = i4 + 1;
        bArr[i4] = (byte) ((i2 >> 16) & HeartRateInfo.HR_EMPTY_VALUE);
        i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >> 24) & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static void m25329a(byte[] bArr, int i, short s) {
        int i2 = i + 1;
        bArr[i] = (byte) ((s >> 0) & HeartRateInfo.HR_EMPTY_VALUE);
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((s >> 8) & HeartRateInfo.HR_EMPTY_VALUE);
    }

    public static byte[] m25331a(byte[] bArr, byte[] bArr2) {
        try {
            Cipher instance = Cipher.getInstance("AES/ECB/NoPadding");
            instance.init(1, new SecretKeySpec(bArr, "AES"));
            return instance.doFinal(bArr2);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        } catch (NoSuchPaddingException e2) {
            e2.printStackTrace();
            return null;
        } catch (InvalidKeyException e3) {
            e3.printStackTrace();
            return null;
        } catch (IllegalBlockSizeException e4) {
            e4.printStackTrace();
            return null;
        } catch (BadPaddingException e5) {
            e5.printStackTrace();
            return null;
        }
    }

    public static int m25332b(UUID uuid) {
        long mostSignificantBits = uuid.getMostSignificantBits();
        return (uuid.getLeastSignificantBits() == f19572i && (4294967295L & mostSignificantBits) == f19571h) ? (int) (mostSignificantBits >> 32) : 0;
    }

    public static int m25333b(byte[] bArr, int i, int i2) {
        if (i >= bArr.length || i > i2) {
            return 0;
        }
        int i3 = SupportMenu.USER_MASK;
        while (i < i2) {
            i3 = (((i3 << 8) | (i3 >>> 8)) & SupportMenu.USER_MASK) ^ (bArr[i] & HeartRateInfo.HR_EMPTY_VALUE);
            i3 ^= (i3 & HeartRateInfo.HR_EMPTY_VALUE) >> 4;
            i3 ^= (i3 << 12) & SupportMenu.USER_MASK;
            i3 ^= ((i3 & HeartRateInfo.HR_EMPTY_VALUE) << 5) & SupportMenu.USER_MASK;
            i++;
        }
        return i3 & SupportMenu.USER_MASK;
    }

    public static String m25334b(int i) {
        StringBuilder stringBuilder = new StringBuilder();
        if ((i & 1) > 0) {
            stringBuilder.append("BROADCAST ");
        }
        if ((i & AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) > 0) {
            stringBuilder.append("EXTENDED_PROPS ");
        }
        if ((i & 32) > 0) {
            stringBuilder.append("INDICATE ");
        }
        if ((i & 16) > 0) {
            stringBuilder.append("NOTIFY ");
        }
        if ((i & 2) > 0) {
            stringBuilder.append("READ ");
        }
        if ((i & 64) > 0) {
            stringBuilder.append("SIGNED_WRITE ");
        }
        if ((i & 8) > 0) {
            stringBuilder.append("WRITE ");
        }
        if ((i & 4) > 0) {
            stringBuilder.append("WRITE_NO_RESPONSE ");
        }
        return stringBuilder.toString();
    }

    public static String m25335b(byte[] bArr) {
        GuliLog.ASSERT_NOT_NULL((Object) bArr);
        if (bArr == null || bArr.length == 0) {
            return C3657a.f18328f;
        }
        StringBuilder stringBuilder = new StringBuilder();
        int length = bArr.length;
        for (int i = 0; i < length; i++) {
            stringBuilder.append(String.format("%02x ", new Object[]{Byte.valueOf(bArr[i])}));
        }
        return stringBuilder.substring(0, stringBuilder.length() - 1);
    }

    public static UUID m25336b(String str) {
        return UUID.fromString(str);
    }

    public static byte[] m25337b(byte[] bArr, byte[] bArr2) {
        try {
            Cipher instance = Cipher.getInstance("AES/ECB/NoPadding");
            instance.init(2, new SecretKeySpec(bArr, "AES"));
            return instance.doFinal(bArr2);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        } catch (NoSuchPaddingException e2) {
            e2.printStackTrace();
            return null;
        } catch (InvalidKeyException e3) {
            e3.printStackTrace();
            return null;
        } catch (IllegalBlockSizeException e4) {
            e4.printStackTrace();
            return null;
        } catch (BadPaddingException e5) {
            e5.printStackTrace();
            return null;
        }
    }

    public static int m25338c(byte[] bArr) {
        int i = SupportMenu.USER_MASK;
        for (byte b : bArr) {
            i = (((i << 8) | (i >>> 8)) & SupportMenu.USER_MASK) ^ (b & HeartRateInfo.HR_EMPTY_VALUE);
            i ^= (i & HeartRateInfo.HR_EMPTY_VALUE) >> 4;
            i ^= (i << 12) & SupportMenu.USER_MASK;
            i ^= ((i & HeartRateInfo.HR_EMPTY_VALUE) << 5) & SupportMenu.USER_MASK;
        }
        return i & SupportMenu.USER_MASK;
    }

    public static int m25339c(byte[] bArr, int i, int i2) {
        int i3 = 0;
        int i4 = 0;
        while (i3 < i2) {
            i4 |= (bArr[i + i3] & HeartRateInfo.HR_EMPTY_VALUE) << (i3 * 8);
            i3++;
        }
        return i4;
    }

    public static String m25340c(int i) {
        StringBuilder stringBuilder = new StringBuilder();
        if ((i & 1) > 0) {
            stringBuilder.append("READ ");
        }
        if ((i & 2) > 0) {
            stringBuilder.append("READ_ENCRYPTED ");
        }
        if ((i & 4) > 0) {
            stringBuilder.append("READ_ENCRYPTED_MITM ");
        }
        if ((i & 16) > 0) {
            stringBuilder.append("WRITE ");
        }
        if ((i & 32) > 0) {
            stringBuilder.append("WRITE_ENCRYPTED ");
        }
        if ((i & 64) > 0) {
            stringBuilder.append("WRITE_ENCRYPTED_MITM ");
        }
        if ((i & AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) > 0) {
            stringBuilder.append("WRITE_SIGNED ");
        }
        if ((i & PersonInfo.INCOMING_CALL_DISABLE_BIT) > 0) {
            stringBuilder.append("WRITE_SIGNED_MITM ");
        }
        return stringBuilder.toString();
    }

    public static String m25341c(UUID uuid) {
        String uuid2 = uuid.toString();
        return uuid2.matches(f19570g) ? uuid2.substring(4, 8) : uuid2;
    }

    public static int m25342d(byte[] bArr) {
        int i = 0;
        for (byte b : bArr) {
            i ^= b & HeartRateInfo.HR_EMPTY_VALUE;
            for (int i2 = 0; i2 < 8; i2++) {
                i = (i & 1) != 0 ? ((i >> 1) & HeartRateInfo.HR_EMPTY_VALUE) ^ 140 : (i >> 1) & HeartRateInfo.HR_EMPTY_VALUE;
            }
        }
        return i;
    }

    public static C3907e m25343e(byte[] bArr) {
        GuliLog.ASSERTION_TRUE(bArr.length == 62);
        C3907e c3907e = new C3907e();

        //  TBD DEBUG
        int i10;
        StringBuilder debugStringBuilder = new StringBuilder();

        for (i10 = 0; i10 < bArr.length; i10++)
        {
            debugStringBuilder.append(bArr[i10]);
            debugStringBuilder.append(" ");
        }

        Log.e(TAG, debugStringBuilder.toString());

        int i = 0;
        while (i < 62) {
            int i2 = i + 1;
            byte b = bArr[i];
            if (b != 0 && b + i2 <= 62) {
                int i3 = i2 + 1;
                byte[] bArr2;
                String b2;
                StringBuilder stringBuilder;
                int position;
                int i4;
                byte[] bArr3;
                switch (bArr[i2]) {
                    // to get the manufacture information
                    case BLE_MANUFACTURE_SPEC_DATA /*-1*/:
                        position = i2;
                        /* By FRK solution, we can get the scale weight information and MAC address in the scanned information.
                        A. we can check the manufacture company ID and Product ID
                        B. if it does match, then we can check the current status of scaling.
                            1. we can have 2 methods, first one, we can check if it is the 3, if yes, then we can take the weight scale and
                            to make sure it is in a range 0kg-150kg.
                            2. second one, we can check if there is 2 to 3 state machine change, if yes, we can think it is our devices, and check
                            the weight range.
                        C. we can get the last 6 bytes as the MAC address and compare with what we found in the scaned device address.
                        D. Basically, we can think we already found our devices here and we can make a fake UUID as the scanner expected and move on
                        to connection.

                        E. fake information we need.
                            1. UUID
                            2. timestamp.
                        */
                        bArr2 = new byte[(b - 1)];
                        i = i3;
                        i3 = 0;
                        while (i3 < b - 1) {
                            i2 = i + 1;
                            bArr2[i3] = bArr[i];
                            i3++;
                            i = i2;
                        }
                        if ( b == 27 ) {
                            byte[] tempByteArray = new byte[2];
                            // to get the manufacture ID
                            tempByteArray[0] = bArr[position + 1];
                            tempByteArray[1] = bArr[position + 2];

                            String manufacutreID = FrkGattUtils.m25335b(tempByteArray);

                            // to get the production ID
                            tempByteArray[0] = bArr[position + 3];
                            tempByteArray[1] = bArr[position + 4];

                            String productionID = FrkGattUtils.m25335b(tempByteArray);

                            // to get the current status
                            byte scaleStatus = bArr[position + 5];

                            byte[] devMacAddrArray = new byte[6];
                            String devMacAddr;
                            i3 = 0;
                            while (i3 < 6) {
                                devMacAddrArray[i3] = bArr[position + 22 + i3];
                                i3++;
                            }
                            devMacAddr = FrkGattUtils.m25335b(devMacAddrArray);

                            if (manufacutreID.equals("b4 00") && productionID.equals("b1 00") && ((scaleStatus != 1))) {
                                c3907e.devMacAddr = devMacAddr;
                                byte[] fakeInfo = new byte[10];
                                // to build the fake timestamp.
                                Calendar gregorianCalendar = new GregorianCalendar();
                                int year = gregorianCalendar.get(Calendar.YEAR);

                                fakeInfo[0] = 17;
                                if ((scaleStatus == 3)) {
                                    fakeInfo[0] += (byte)ScaleWeightInfo.stable;
                                }

                                else if (scaleStatus == 1)
                                {
                                    // for sleep broadcast, we can ignore it;
                                    fakeInfo[0] = 0;
                                }
                                else if (scaleStatus == 2)
                                {
                                    // do nothing now
                                }
                                else {
//                                    fakeInfo[0] += (byte)ScaleWeightInfo.finish;
                                }

                                int weightValue = ((0xff & bArr[position + 7]) << 8 | (0xff &bArr[position + 6]));

                                weightValue = weightValue * 10 ;
                                fakeInfo[1] = (byte)(weightValue & 0xff);
                                fakeInfo[2] = (byte)((weightValue >> 8)& 0xff);
                                fakeInfo[3] = (byte)(year & 0xff);
                                fakeInfo[4] = (byte)((year >> 8) & 0xff);
                                fakeInfo[5] = (byte)(gregorianCalendar.get(Calendar.MONTH) + 1);
                                fakeInfo[6] = (byte)(gregorianCalendar.get(Calendar.DATE));
                                fakeInfo[7] = (byte)(gregorianCalendar.get(Calendar.HOUR_OF_DAY));
                                fakeInfo[8] = (byte)(gregorianCalendar.get(Calendar.MINUTE));
                                //fakeInfo[9] = (byte)(gregorianCalendar.get(Calendar.SECOND));
                                fakeInfo[9] = 0;
                                c3907e.scaleWeightInfo = ProfileUtils.m25641a(fakeInfo, false, false);

                                c3907e.serv16.add("181D");
                                WeightProfile profile = XMBLEManager.m25164i();
                                if (profile != null)
                                    profile.setDevType(Constants.DEV_FRK_SCALE);
                            }

                        } else {
                            b2 = FrkGattUtils.m25335b(bArr2);
                            // here need to get the manufacture ID

                            c3907e.manufact = b2;
                            GuliLog.m12350a("    manufact: " + b2);
                        }
                        // ge
                        continue;
                        // to get the flag
                    case BLE_FLAGS /*1*/:
                        GuliLog.ASSERTION_TRUE(b == 2);
                        i = i3 + 1;
                        byte tempbyte = bArr[i3];
                        c3907e.flags = tempbyte;
                        GuliLog.m12350a("        flag: " + String.format("%02x", new Object[]{Byte.valueOf(bArr[i3])}));// TBDr1

                        continue; // get this from decompile website instead of JADX
                        // to get the *serv16, the UUID information
                    case BLE_INCOMPLETE_16BITS_UUID /*2*/:
                        stringBuilder = new StringBuilder();
                        i4 = 0;
                        i = i3;
                        while (i4 < b - 1) {
                            bArr3 = new byte[2];
                            i3 = i;
                            i = 0;
                            while (i < 2) {
                                i2 = i3 + 1;
                                bArr3[i] = bArr[i3];
                                i++;
                                i3 = i2;
                            }
                            c3907e.inServ16.add(String.format("%02x%02x", new Object[]{Byte.valueOf(bArr3[1]), Byte.valueOf(bArr3[0])}));
                            stringBuilder.append(GattUtils.m25335b(bArr3));
                            stringBuilder.append("; ");
                            i4 += 2;
                            i = i3;
                        }
                        GuliLog.m12350a("   (*)serv16: " + stringBuilder.toString());
                        continue;
                        // to get the serv16, the UUID information
                    case BLE_COMPLETE_16BITS_UUID /*3*/:
                        stringBuilder = new StringBuilder();
                        i4 = 0;
                        i = i3;
                        while (i4 < b - 1) {
                            bArr3 = new byte[2];
                            i3 = i;
                            i = 0;
                            while (i < 2) {
                                i2 = i3 + 1;
                                bArr3[i] = bArr[i3];
                                i++;
                                i3 = i2;
                            }
                            c3907e.serv16.add(String.format("%02x%02x", new Object[]{Byte.valueOf(bArr3[1]), Byte.valueOf(bArr3[0])}));
                            stringBuilder.append(GattUtils.m25335b(bArr3));
                            stringBuilder.append("; ");
                            i4 += 2;
                            i = i3;
                        }
                        GuliLog.m12350a("      serv16: " + stringBuilder.toString());
                        continue;
                        // to get the serv128, full UUID information
                    case BLE_INCOMPLETE_128BITS_UUID /*6*/:
                        stringBuilder = new StringBuilder();
                        i4 = 0;
                        i = i3;
                        while (i4 < b - 1) {
                            bArr3 = new byte[16];
                            i3 = i;
                            i = 0;
                            while (i < 16) {
                                i2 = i3 + 1;
                                bArr3[i] = bArr[i3];
                                i++;
                                i3 = i2;
                            }
                            c3907e.inServ128.add(String.format("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", new Object[]{Byte.valueOf(bArr3[15]), Byte.valueOf(bArr3[14]), Byte.valueOf(bArr3[13]), Byte.valueOf(bArr3[12]), Byte.valueOf(bArr3[11]), Byte.valueOf(bArr3[10]), Byte.valueOf(bArr3[9]), Byte.valueOf(bArr3[8]), Byte.valueOf(bArr3[7]), Byte.valueOf(bArr3[6]), Byte.valueOf(bArr3[5]), Byte.valueOf(bArr3[4]), Byte.valueOf(bArr3[3]), Byte.valueOf(bArr3[2]), Byte.valueOf(bArr3[1]), Byte.valueOf(bArr3[0])}));
                            stringBuilder.append(GattUtils.m25335b(bArr3));
                            stringBuilder.append("; ");
                            i4 += 16;
                            i = i3;
                        }
                        GuliLog.m12350a("  (*)serv128: " + stringBuilder.toString());
                        continue;
                        // to get the serv128, full UUID information
                    case BLE_COMPLETE_128BITS_UUID /*7*/:
                        stringBuilder = new StringBuilder();
                        i4 = 0;
                        i = i3;
                        while (i4 < b - 1) {
                            bArr3 = new byte[16];
                            i3 = i;
                            i = 0;
                            while (i < 16) {
                                i2 = i3 + 1;
                                bArr3[i] = bArr[i3];
                                i++;
                                i3 = i2;
                            }
                            c3907e.serv128.add(String.format("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", new Object[]{Byte.valueOf(bArr3[15]), Byte.valueOf(bArr3[14]), Byte.valueOf(bArr3[13]), Byte.valueOf(bArr3[12]), Byte.valueOf(bArr3[11]), Byte.valueOf(bArr3[10]), Byte.valueOf(bArr3[9]), Byte.valueOf(bArr3[8]), Byte.valueOf(bArr3[7]), Byte.valueOf(bArr3[6]), Byte.valueOf(bArr3[5]), Byte.valueOf(bArr3[4]), Byte.valueOf(bArr3[3]), Byte.valueOf(bArr3[2]), Byte.valueOf(bArr3[1]), Byte.valueOf(bArr3[0])}));
                            stringBuilder.append(GattUtils.m25335b(bArr3));
                            stringBuilder.append("; ");
                            i4 += 16;
                            i = i3;
                        }
                        GuliLog.m12350a("     serv128: " + stringBuilder.toString());
                        continue;
                        // to get the name
                    case BLE_SHORTENED_LOCAL_NAME /*8*/:
                        bArr2 = new byte[(b - 1)];
                        i = i3;
                        i3 = 0;
                        while (i3 < b - 1) {
                            i2 = i + 1;
                            bArr2[i3] = bArr[i];
                            i3++;
                            i = i2;
                        }
                        b2 = new String(bArr2);
                        c3907e.shortLocalName = b2;
                        GuliLog.m12350a("     (*)name: " + b2);
                        continue;
                        // to get the name
                    case BLE_COMPLETE_LOCAL_NAME /*9*/:
                        bArr2 = new byte[(b - 1)];
                        i = i3;
                        i3 = 0;
                        while (i3 < b - 1) {
                            i2 = i + 1;
                            bArr2[i3] = bArr[i];
                            i3++;
                            i = i2;
                        }
                        b2 = new String(bArr2);
                        c3907e.localName = b2;
                        GuliLog.m12350a("        name: " + b2);
                        continue;
                        // to get the tx level, looks like it is related to the signal strength of bluetooth
                    case BLE_TX_POWER_LEVEL /*10*/:
                        bArr2 = new byte[(b - 1)];
                        i = i3;
                        i3 = 0;
                        while (i3 < b - 1) {
                            i2 = i + 1;
                            bArr2[i3] = bArr[i];
                            i3++;
                            i = i2;
                        }
                        b2 = GattUtils.m25335b(bArr2);
                        c3907e.txLevel = b2;
                        GuliLog.m12350a("    tx level: " + b2);
                        continue;
                        // to get solicit16
                    case BLE_16BITS_SER_SOL_UUID /*20*/:
                        stringBuilder = new StringBuilder();
                        i4 = 0;
                        i = i3;
                        while (i4 < b - 1) {
                            bArr3 = new byte[2];
                            i3 = i;
                            i = 0;
                            while (i < 2) {
                                i2 = i3 + 1;
                                bArr3[i] = bArr[i3];
                                i++;
                                i3 = i2;
                            }
                            stringBuilder.append(GattUtils.m25335b(bArr3));
                            stringBuilder.append("; ");
                            i4 += 2;
                            i = i3;
                        }
                        c3907e.solicit16 = stringBuilder.toString();
                        GuliLog.m12350a("   solicit16: " + stringBuilder.toString());
                        continue;
                        // to get solicit128
                    case BLE_128BITS_SER_SOL_UUID /*21*/:
                        stringBuilder = new StringBuilder();
                        i4 = 0;
                        i = i3;
                        while (i4 < b - 1) {
                            bArr3 = new byte[16];
                            i3 = i;
                            i = 0;
                            while (i < 16) {
                                i2 = i3 + 1;
                                bArr3[i] = bArr[i3];
                                i++;
                                i3 = i2;
                            }
                            stringBuilder.append(GattUtils.m25335b(bArr3));
                            stringBuilder.append("; ");
                            i4 += 16;
                            i = i3;
                        }
                        c3907e.solicit128 = stringBuilder.toString();
                        GuliLog.m12350a("  solicit128: " + stringBuilder.toString());
                        continue;
                        // to get weightinfo
                    case BLE_SERVICE_DATA /*22*/:
                        byte[] obj = new byte[(b - 1)];
                        i = i3;
                        i3 = 0;
                        while (i3 < b - 1) {
                            i2 = i + 1;
                            obj[i3] = bArr[i];
                            i3++;
                            i = i2;
                        }
                        if (obj.length != 12) {
                            c3907e.scaleWeightInfo = ProfileUtils.m25641a(obj, false, false);
                            break;
                        }
                        if (!C3923a.y_.equals(GattUtils.m25322a(String.format("%02X%02X", new Object[]{Byte.valueOf(obj[1]), Byte.valueOf(obj[0])})))) {
                            GuliLog.m12370d(TAG, "UUID is not UUID_SERVICE_WEIGHT_SCALE_SERVICE<181D>!!!");
                            break;
                        }
                        byte[] obj2 = new byte[(obj.length - 2)];
                        System.arraycopy(obj, 2, obj2, 0, obj2.length);
                        c3907e.scaleWeightInfo = ProfileUtils.m25641a(obj2, false, false);
                        continue;
                    default:
                        byte[] bArr4 = new byte[(b - 1)];
                        i = i3;
                        i3 = 0;
                        while (i3 < b - 1) {
                            i2 = i + 1;
                            bArr4[i3] = bArr[i];
                            i3++;
                            i = i2;
                        }
                        c3907e.other = String.format("[0x%02x]", new Object[]{Byte.valueOf(bArr4[i3])}) + ": " + GattUtils.m25335b(bArr4);
                        GuliLog.m12350a("      " + String.format("[0x%02x]", new Object[]{Byte.valueOf(bArr4[i3])}) + ": " + GattUtils.m25335b(bArr4));
                        break;
                }
            }
            return c3907e;
        }
        return c3907e;
    }

    private static int m25344f(byte[] bArr) {
        int i = 0;
        int length = bArr.length;
        int i2 = 0;
        while (i < length) {
            int i3 = i2 >>> 8;
            i2 = f19573j[(i2 ^ bArr[i]) & HeartRateInfo.HR_EMPTY_VALUE] ^ i3;
            i++;
        }
        return i2;
    }
}

